package com.suray.basic.wcs.time.bo;

import com.suray.basic.wcs.path.core.Node;
import com.suray.basic.wcs.utils.Coord;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WCSTimeModuleResultBO<T> {
    private T result;
    private List<Node> nodes;
    private Map<String, Node> nodeMap;
    private int totalTime;

    public WCSTimeModuleResultBO() {
        nodes = new ArrayList<>();
        nodeMap = new HashMap<>();
    }
    public WCSTimeModuleResultBO(T result) {
        this.result = result;
        nodes = new ArrayList<>();
        nodeMap = new HashMap<>();
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public List<Node> getNodes() {
        return nodes;
    }

    public void setNodes(List<Node> nodes) {
        this.nodes = nodes;
        nodeMap.clear();
        if(this.nodes != null) {
            for (Node node : nodes) {
                nodeMap.put(node.toString(), node);
            }
        }
    }

    public int getTotalTime() {
        return totalTime;
    }

    public void setTotalTime(int totalTime) {
        this.totalTime = totalTime;
    }

    public Map<String, Node> getNodeMap() {
        return nodeMap;
    }

    public void setNodeMap(Map<String, Node> nodeMap) {
        this.nodeMap = nodeMap;
    }

    public Node getNode(Coord coord){
        return nodeMap.get(coord.toString());
    }

    public Node getNode(String string){
        return nodeMap.get(string);
    }
}
